﻿package Game;

import java.net.*;

import Map.GameMap;
import Unit.UnitMonk;
import User.GameUser;

public class GameServer
{
	private ServerSocket serverSocket;
	private GameManager gameManager;
	private int MatchType;

	public GameServer(int MatchType)
	{
		//우선 여기서 초기화해준다.
		this.MatchType=MatchType;
		gameManager=new GameManager(MatchType);
	}
	
	public void WaitClient()
	{
		try
		{
			serverSocket=new ServerSocket(5000);
			System.out.println("Server socket is created.");
			while(true)
			{
				Socket socketClient=serverSocket.accept();
				GameUser gameUser=new GameUser(gameManager, socketClient);
				gameUser.start();
				gameManager.AddUser(gameUser);
				//게임 시작 가능한지 검사
				//gameManager.CheckStart();
				//나중에 되면 게임 시작할때 추가로 accept하지 않고 시작하도록 해본다.
			}
		}
		catch(Exception e)
		{
			//System.out.println(e.getMessage());
		}
	}
	
	public void EndGame()
	{
	}
	
	public static void main(String[] args)
	{
		int arg;
		//1:1, 2:2는 args로 받아서 한다.
		if(args.length>0)
		{
			arg=Integer.valueOf(args[0]).intValue();
			GameServer gameServer=new GameServer(arg);
			gameServer.WaitClient();
		}
	}
}